

#ifndef HASH_MAP_H
#define HASH_MAP_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>

typedef struct hashmap_node
{
	uint8_t *key;
	uint8_t *value;
	struct hashmap_node **pprev,*next; /**/
}HASHMAP_NODE;

typedef struct  hashmap_head {
    HASHMAP_NODE *first; 
}HASHMAP_HEAD;

typedef struct hashmap_mng
{
	HASHMAP_HEAD *hashhead;
	int hashnum;
}HASHMAP_MNG;

typedef struct {
	uint32_t hashvalue;
	HASHMAP_NODE *nodes;
}HASHMAP_FIND_ITEM;


typedef int (*F_HASH_COMPARE)(uint8_t *oldkey,uint8_t *newkey);
typedef int (*F_HASH)(uint8_t *key,uint32_t *hashval);
typedef int (*F_LISTTODO)(uint8_t *key,uint32_t *value);
typedef int (*F_FIND)(HASHMAP_NODE *node);



HASHMAP_MNG *create_hashmap(int maxnum);
int destory_hashmap(HASHMAP_MNG *hashmng);
int hashmap_add_key(HASHMAP_MNG *hashmng,uint8_t *key,uint8_t *value,F_HASH hash,F_HASH_COMPARE compare_fn );
int hashmap_add_hashkey(HASHMAP_MNG *hashmng,uint32_t hashvalue,uint8_t *key,uint8_t *value,F_HASH_COMPARE compare_fn );
int hashmap_add_node(HASHMAP_MNG *hashmng,uint32_t hashvalue,HASHMAP_NODE *node,F_HASH_COMPARE compare_fn );
int hashmap_del_key(HASHMAP_MNG *hashmng,uint8_t *key,F_HASH hash,F_HASH_COMPARE compare_fn);
int hashmap_del_hashkey(HASHMAP_MNG *hashmng,uint32_t hashvalue,uint8_t *key,F_HASH_COMPARE compare_fn);
int hashmap_del_hashkey(HASHMAP_MNG *hashmng,uint32_t hashvalue,uint8_t *key,F_HASH_COMPARE compare_fn);
int hashmap_del_node(HASHMAP_MNG *hashmng,uint32_t hashvalue,HASHMAP_NODE *node,F_HASH_COMPARE compare_fn);
int hashmap_get_value(HASHMAP_MNG *hashmng,uint8_t *key,F_HASH hash,uint8_t **value,F_HASH_COMPARE compare_fn);
int hashmap_get_value_by_hashkey(HASHMAP_MNG *hashmng,uint32_t hashvalue,uint8_t *key,uint8_t **value,F_HASH_COMPARE compare_fn);
int hashmap_check_keyexist(HASHMAP_MNG *hashmng,uint8_t *key,F_HASH hash,F_HASH_COMPARE compare_fn);
int hashmap_is_empty(HASHMAP_MNG *hashmng);
int hashmap_list_all(HASHMAP_MNG *hashmng,F_LISTTODO todo);
int hashmap_find_node(HASHMAP_MNG *hashmng,F_FIND find,HASHMAP_FIND_ITEM *item,int num);

#endif


